####################################################################################
########                       BlackBirdDaemon                               #######
########                       Scopel Emanuele                               #######
########                      escopel@alice.it                               #######
########                         license GPL3                                #######
####################################################################################



import time
from twisted.application import internet, service
from twisted.internet import protocol
from twisted.python import log

UDP_PORT = 40200

class Receiver(protocol.DatagramProtocol):

    def datagramReceived(self, data, (ip, port)):
        if data == 'hello':
            self.transport.write('hello client', (ip, port))	
        else:
            self.transport.write('OK', (ip, port))	
            log.msg('Client %s %s' % (ip, data))
            

        
application = service.Application('BlackBirdDaemon_Server')
receiver = Receiver( )
udpServer = internet.UDPServer(UDP_PORT, receiver)
udpServer.setServiceParent(application)
log.msg('Asynchronous BlackBirdDaemon_Server listening on port %d\n'
    'press Ctrl-C to stop\n' % UDP_PORT)

#start command twistd -ony ./server.py
